<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/17
 * Time: 22:55
 */
namespace app\common\lib\exception;
use think\exception\Handle;
class ApiHandleException    extends Handle
{
    /**
     * @var int $httpcode 默认网站状态码
     */
    public $httpcode=500;

    public function render(\Exception $e){
        /**
         * 加上判断，如果是api抛出异常，那么返回的是api自定义httpcode。
         * 如果是源程序自带报错，那么返回我们写死的500
         */
//        if(config('app_debug')==true){
//            return parent::render($e);
//        }
        if($e instanceof ApiException){
            $this->httpcode = $e->httpcode;
        }
        return show(500,$e->getMessage(),[],$this->httpcode);
    }
}